package com.oneplus.extend.Universal;

import com.oneplus.extend.compiler.RegexCompile;

import java.util.regex.Pattern;

public enum TypeEnum {
    //
    str,
    num,
    integer,
    coin,
    time,
    arr,
    address;

    public static String matchTypeByRegex(String type) {
        String result = "";
        switch (type) {
            case "str":
                result  = "^\"([^\"]*)\"$";
                break;
            case "num":
                result = "^([0-9]{1,}[.][0-9]*)$";
                break;
            case "coin":
                result = "^\\d+$";
                break;
            case "integer":
                result = "^\\d+$";
                break;
            case "address":
                result = "\\w+";
                break;
            case "time":
                result = "^\"[1-9]\\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\\s+(20|21|22|23|[0-1]\\d):[0-5]\\d:[0-5]\\d\"$";
                break;
            case "arr":
                result = "\\[(\"([^\"]*)\"|,\"([^\"]*)\")+\\]";
                break;
            default:
                break;
        }
        return result;
    }

    //正则不包含数字
    public static boolean checkLetterLine(String str) {
        String reg = "([A-Z]|[a-z]|-|_){1,}";
        if (Pattern.matches(reg, str)) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean matchType(String typeStr) {
        for (TypeEnum typeEnum : TypeEnum.values()) {
            if (typeEnum.name().equals(typeStr)) {
                return true;
            }
        }
        return false;
    }

    public static boolean matchTypeVar(String type, String typeStr1, String typeStr2) {
        String reg = matchTypeByRegex(type);
        if (Pattern.matches(reg, typeStr1) && Pattern.matches(reg, typeStr2)) {
            return true;
        } else {
            return false;
        }
    }
}
